package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> list(@PathVariable Long id){
        log.info("根据id查询套餐：{}",id);
            SetmealVO setmealVo = setmealService.getById(id);
            return Result.success(setmealVo);
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result setSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.insert(setmealDTO);
        return Result.success();
    }

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询套餐")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult page = setmealService.getQueryPage(setmealPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 根据id批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据id批量删除")
    public Result deleteById(@RequestParam List<Long> ids){
        setmealService.deleteById(ids);
        return Result.success();
    }

    /**
     * 修改套餐数据
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐数据")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("要修改的套餐数据：{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    /**
     * 根据id修改启售停售状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("根据id修改启售停售状态")
    public Result setStatus(@PathVariable Integer status, Long id){
        log.info("准备启售和停售的套餐是：{},{}",status,id);
        setmealService.setStatusById(status,id);
        return Result.success();
    }
}
